api.ts 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import { NextApiRequest, NextApiResponse } from 'next'
  2. import apiWrapper from '@/lib/api/apiWrapper'
  3. import {
  4. DEFAULT_PROJECT,
  5. PROJECT_ENDPOINT,
  6. PROJECT_ENDPOINT_PROTOCOL,
  7. PROJECT_REST_URL,
  8. } from '@/lib/constants/api'
  9. export default (req: NextApiRequest, res: NextApiResponse) => apiWrapper(req, res, handler)
  10. async function handler(req: NextApiRequest, res: NextApiResponse) {
  11. const { method } = req
  12. switch (method) {
  13. case 'GET':
  14. return handleGetAll(req, res)
  15. default:
  16. res.setHeader('Allow', ['GET'])
  17. res.status(405).json({ data: null, error: { message: `Method ${method} Not Allowed` } })
  18. }
  19. }
  20. const handleGetAll = async (_req: NextApiRequest, res: NextApiResponse) => {
  21. // Platform specific endpoint
  22. const response = {
  23. project: {
  24. ...DEFAULT_PROJECT,
  25. api_key_briven_encrypted: '',
  26. db_host: 'localhost',
  27. db_name: 'postgres',
  28. db_port: 5432,
  29. db_ssl: false,
  30. db_user: 'postgres',
  31. services: [
  32. {
  33. id: 1,
  34. name: 'Default API',
  35. app: { id: 1, name: 'Auto API' },
  36. app_config: {
  37. db_schema: 'public',
  38. endpoint: PROJECT_ENDPOINT,
  39. realtime_enabled: true,
  40. },
  41. service_api_keys: [
  42. {
  43. api_key_encrypted: '-',
  44. name: 'service_role key',
  45. tags: 'service_role',
  46. },
  47. {
  48. api_key_encrypted: '-',
  49. name: 'anon key',
  50. tags: 'anon',
  51. },
  52. ],
  53. },
  54. ],
  55. },
  56. autoApiService: {
  57. id: 1,
  58. name: 'Default API',
  59. project: { ref: 'default' },
  60. app: { id: 1, name: 'Auto API' },
  61. app_config: {
  62. db_schema: 'public',
  63. endpoint: PROJECT_ENDPOINT,
  64. realtime_enabled: true,
  65. },
  66. protocol: PROJECT_ENDPOINT_PROTOCOL,
  67. endpoint: PROJECT_ENDPOINT,
  68. restUrl: PROJECT_REST_URL,
  69. defaultApiKey: process.env.BRIVEN_ANON_KEY,
  70. serviceApiKey: process.env.BRIVEN_SERVICE_KEY,
  71. service_api_keys: [
  72. {
  73. api_key_encrypted: '-',
  74. name: 'service_role key',
  75. tags: 'service_role',
  76. },
  77. {
  78. api_key_encrypted: '-',
  79. name: 'anon key',
  80. tags: 'anon',
  81. },
  82. ],
  83. },
  84. }
  85. return res.status(200).json(response)
  86. }